<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <strong v-if="isCompany">{{ nodeData.name }}</strong>
      <span v-else>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown trigger="click">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartments">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="delDepartments">删除子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="updateDepartment">查看子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col></el-row>
</template>
b
<script>
import { delDepartment } from '@/api/department.js'
export default {
  props: {
    nodeData: { type: Object, required: true
    },
    isCompany: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 删除部门
    async delDepartments() {
      // console.log(123)
      // 二次询问
      await this.$confirm('确认删除吗？')
      // 发删除请求
      await delDepartment(this.nodeData.id)
      // 提示用户
      this.$message.success('删除成功')
      // 更新页面（通知父组件获取数据）
      this.$emit('delupdateList')
    },
    // 添加子部门
    addDepartments() {
      // console.log(49, this.nodeData)
      this.$emit('showAddDialog', this.nodeData)
    },
    // 查看and编辑子部门
    updateDepartment() {
      // console.log(123)
      this.$emit('showUpdateDialog', this.nodeData)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
